package com.tau.egonetwork.facebook;

import com.tau.egonetwork.net.AccessToken;
import com.tau.egonetwork.net.IResponse;

public class FacebookAuthResponse implements IResponse {

	private final static String FIELD_ACCESS_TOKEN = "access_token";
	private final static String FIELD_EXPIRES = "expires";
	
	@Override
	public AccessToken parseJSONResponse(String response) {
		
		/* NOTE that this particular response is not really JSON!! */
		
		int x = response.indexOf(FIELD_ACCESS_TOKEN);
		assert(x != -1); //<--- handle as exception later on!!
		int y = response.indexOf(FIELD_EXPIRES);
		
		String accessToken = response.substring(FIELD_ACCESS_TOKEN.length() + 1,
				(y == -1 ? response.length() : y) - 1);
		
		AccessToken token = new AccessToken(accessToken);
		
		return token;
	}

}
